package rickyGame.game.property
{
	import ricky.game.action.Act2D;
	
	import rickyGame.game.Fighter;
	import rickyGame.game.action.ActionHelper;

	/**
	 * 玩家包涵的状态
	 * 暂时不用
	 */
	public class States  extends Act2D
	{
		public function States(fighter:Fighter)
		{
			super(fighter);
			_states=new Array();
			_fighter=fighter;
		}
		
		public function push(act:Act2D):void
		{
			var i:int=_states.indexOf(act);
			if(i==-1)
			{
				_states.push(act);
				act.completeFun=completeFun;
				act.begin();
			}
			
			if(_states.length>0)
			{
				this._running=true;
				this.begin();
			}
		}
		
		override public function begin():void
		{
			ActionHelper.inst.addAct(this);
		}
		
		override public function complete():void
		{
			//没有结束
		}
		
		override public function end():void
		{
//			ActionHelper.inst.removeAct(this);
		}
		
		/**
		 * 不能销毁
		 */
		public function dispose():void
		{
			
		}
		
		public function completeFun(e:Act2D):void
		{
			removeAct(e);
		}
		
		/**
		 * 行动中
		 * @param timeline 当前时间戳
		 */
		public function action(timeline:Number):void
		{
			for each(var act:Act2D in _states)
			{
				act.action(timeline);
			}
		}
		
		/**
		* 删除行动
		*/
		public function removeAct(act:Act2D):void
		{
			var i:int=_states.indexOf(act);
			if(i>=0)
				_states.splice(i,1);
			
			act.end();
			act.dispose();
			
			if(_states.length==0)
			{
				_running=false;
				ActionHelper.inst.removeAct(this);//移除
			}
		}
		
		public function get states():Array
		{
			return _states;
		}
		
		public function set states(value:Array):void
		{
			_states = value;
		}

		public function get fighter():Fighter
		{
			return _fighter;
		}

		public function get running():Boolean
		{
			return _running;
		}


		//
		private var _running:Boolean;
		private var _states:Array;//包括的所有状态
		private var _fighter:Fighter;//对象


	}
}